package com.squeekeek.util.qrcode.Core;

import java.util.List;

import org.opencv.core.Point;

/**
 * <p>
 * A class encapsulating the three finder patterns of a QR Code.
 * </p>
 * 
 * @author Carl
 *
 */
public class QRFinderPattern {
	private Point[] finderCenters = new Point[3];
	private boolean isReordered = false;
	
	public static final int POS_UL = 0x00;
	public static final int POS_UR = 0x01;
	public static final int POS_LL = 0x02;
	
	public QRFinderPattern(Point[] pointVecs) {
		this.finderCenters = pointVecs;
	}
	
	public QRFinderPattern(Point p1, Point p2, Point p3) {
		this.finderCenters[0] = p1;
		this.finderCenters[1] = p2;
		this.finderCenters[2] = p3;
	}
	
	public void reorderOrientation() {
		this.setValue(QRImageCorrection.reorderOrientation(this));
		this.isReordered = true;
	}
	
	public QRFinderPattern(List <Point> pointVecs, boolean setReordered) {
		pointVecs.toArray(this.finderCenters);
		
		this.isReordered = setReordered;
	}
	
	public boolean getReordered() {
		return this.isReordered;
	}

	public Point getPosition(int finderPos) {
		if(isReordered == false) {
			return null;
		}
		
		switch(finderPos) {
		case POS_UL:
			return finderCenters[0];
		case POS_LL:
			return finderCenters[1];
		case POS_UR:
			return finderCenters[2];
		default:
			return null;
		}
	}
	
	public Point[] getArray() {
		return finderCenters;
	}
	
	public void setValue(QRFinderPattern points) {
		this.finderCenters = points.getArray();
	}
	
	public void setValue(Point[] points) {
		this.finderCenters = points;
	}
}
